package com.lunsheng.train

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * @Description
  * @author zhonglunsheng
  * @create 2020-02-10 23:00
  */
object FileWordCount {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[3]").setAppName("WorldCountV2")
    val ssc = new StreamingContext(conf, Seconds(5))
    val lines = ssc.textFileStream("D:/temp")

    val result = lines.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_+_)

    result.print()

    ssc.start()
    ssc.awaitTermination()
  }
}
